.PHONY: bootloader
bootloader: boot.asm loader.asm
	nasm -f bin boot.asm -o boot.bin
	nasm -f bin loader.asm -o loader.bin

master.img: bootloader
	yes | bximage -q -hd=16 -func=create -sectsize=512 -imgmode=flat master.img
	dd if=boot.bin of=master.img bs=512 count=1 conv=notrunc
	dd if=loader.bin of=master.img bs=512 count=4 seek=2 conv=notrunc

.PHONY: usb
usb: boot.bin /dev/sdx
	sudo dd if=/dev/sdx of=tmp.bin bs=512 count=1 conv=notrunc
	cp tmp.bin usb.bin
	sudo rm tmp.bin
	dd if=boot.bin of=usb.bin bs=446 count=1 conv=notrunc
	sudo dd if=usb.bin of=/dev/sdx bs=512 count=1 conv=notrunc
	rm usb.bin

.PHONY: clean
clean:
	rm -rf *.bin
	rm -rf *.img
	rm -rf *.ini

.PHONY: bochs
bochs: master.img
	bochs -q
